﻿using System.Collections.ObjectModel;

namespace Lucy.Editor.Framework
{
    class TreeViewItemViewModel : ViewModel
    {
        public TreeViewItemViewModel Parent { get; protected set; }

        private readonly ObservableCollection<TreeViewItemViewModel> _children;
        public ReadOnlyObservableCollection<TreeViewItemViewModel> Children
        {
            get {return new ReadOnlyObservableCollection<TreeViewItemViewModel>(_children);}
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    FirePropertyChanged("Name");
                }
            }
        }

        private string _icon;
        public string Icon
        {
            get { return _icon; }
            set
            {
                if (_icon != value)
                {
                    _icon = value;
                    FirePropertyChanged("Icon");
                }
            }
        }

        private bool _isExpanded;
        public bool IsExpanded
        {
            get { return _isExpanded; }
            set
            {
                if (_isExpanded != value)
                {
                    _isExpanded = value;
                    FirePropertyChanged("IsExpanded");
                }
            }
        }

        public TreeViewItemViewModel()
        {
            _children = new ObservableCollection<TreeViewItemViewModel>();
        }

        public TreeViewItemViewModel CreateChild(TreeViewItemViewModel treeViewItemViewModel)
        {
            _children.Add(treeViewItemViewModel);
            treeViewItemViewModel.Parent = this;
            return treeViewItemViewModel;
        }

        public void RemoveChild(TreeViewItemViewModel treeViewItemViewModel)
        {
            _children.Remove(treeViewItemViewModel);
        }
    }
}
